# -*- coding: utf-8 -*-

from w.blocks.containers.block import Block
from w.blocks.containers.button import OKButton, ClearButton
from w.blocks.layout.general import NullManager

from w.html.doctypes.preferable import Form as FormTag

from functools import partial

class Form(Block):
    buttonLayout = NullManager

    def __init__(self, content, name, serverUrl='', method='POST', clearButton='',
                 okButton=None, buttonLayout=None, *argv, **kwargv):
        Block.__init__(self, content)

        self.clearButton = clearButton if clearButton!=None else ClearButton('Clear')
        self.okButton = okButton if okButton!=None else OKButton('OK')
        
        if buttonLayout:
            self.buttonLayout = buttonLayout

        self.tag = FormTag(hname=name, haction=serverUrl, hmethod=method, *argv, **kwargv)
        self.html = self.tag.html

    def make(self, content=[]):
        if not content:
            content = self
        self.tag.extend(content+[self.buttonLayout([self.okButton,self.clearButton])])
        return Block.make(self, [self.tag,])
